package exttable.formgenerator;

import exttable.view.ViewTestComboBox;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

import utils.Localisation;

/**
 * Created by IntelliJ IDEA.
 * User: ADMIN
 * Date: 12.07.2010
 * Time: 16:01:54
 * To change this template use File | Settings | File Templates.
 */
public enum EFillValuesToVectorFromComponents {
    SKIP_ELEMENT {
        @Override
        public Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            return null;
        }

    },
    INPUT_TEXT {
        @Override
        public Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            JTextField tf = (JTextField) comp;
            valueVector.add(tf.getText());
            valueOfColumnForInsert.add(tf.getText());
            return valueVector;

        }

    },
    FORMATTED_TEXT_FIELD {
        @Override
        public Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            JFormattedTextField jtf = (JFormattedTextField) comp;
            valueVector.add(jtf.getText());
//            if (jtf.getValue().getClass().getSimpleName().equals("Date")) {
//                valueOfColumnForInsert.add(FormGenerator.returnFormatedData(jtf.getText()));
//            } else {
//                valueOfColumnForInsert.add(jtf.getValue());
//            }
            valueOfColumnForInsert.add(jtf.getText().replace(",",".")); 

             return valueVector;
        }

    },
    TEXT_AREA {
        @Override
        public Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            JTextArea ta = (JTextArea) comp;
            valueVector.add(ta.getText());
            valueOfColumnForInsert.add(ta.getText());
            return valueVector;
        }

    },


    SELECT_ONE_MENU {
        @Override
        public Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            JComboBox jcb = (JComboBox) comp;
            valueVector.add(jcb.getSelectedItem());
            ViewTestComboBox vTCB = (ViewTestComboBox) jcb.getSelectedItem();
            valueOfColumnForInsert.add(vTCB.getId());
            return valueVector;
        }

    },

    PANEL {
        @Override
        public Vector<Object> caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert) {
            JPanel jp = (JPanel) comp;
            if (jp.getComponent(0) instanceof JRadioButton) {
                JRadioButton rb1 = (JRadioButton) jp.getComponents()[0];
                if (rb1.isSelected()) {
                    valueVector.add(Localisation.getMessage("form.yes"));
                    valueOfColumnForInsert.add(1);
                } else {
                    valueVector.add(Localisation.getMessage("form.no"));
                    valueOfColumnForInsert.add(0);
                }
            }
            else if(jp.getComponent(0) instanceof JTextField){
                 JFormattedTextField jtf = (JFormattedTextField) jp.getComponents()[0];
            valueVector.add(jtf.getText());
//                System.out.println("date : "+jtf.getText());
//            if (jtf.getValue().getClass().getSimpleName().equals("Date")) {
                valueOfColumnForInsert.add(StaticMethods.returnFormatedData(jtf.getText()));
//            }


            }
            return valueVector;
        }
    };

    public abstract Vector<Object>  caseDependenceFromClass(Component comp, Vector<Object> valueVector, Vector<Object> valueOfColumnForInsert);



}
